package com.bayair.doctor.net;

import com.bayair.doctor.biz.helper.SpSetting;
import com.blankj.utilcode.util.EncryptUtils;
import com.google.gson.Gson;
import java.io.File;
import java.util.HashMap;
import java.util.Random;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RxParams {

    private static final Gson gson = new Gson();
    private static final Random random = new Random();


    public static HashMap<String, String> getCall(String to, String from) {
        HashMap<String, String> map = new HashMap<>();
        map.put("to", to);
        map.put("from", from);
        return map;
    }

    public static HashMap<String, String> getRounds(String to, String from) {
        HashMap<String, String> map = new HashMap<>();
        map.put("to", to);
        map.put("from", from);
        return map;
    }

    public static HashMap<String, String> getPhysiotherapie(String username, String physiotherapietime, String videourl) {
        HashMap<String, String> map = new HashMap<>();
        map.put("username", username);
        map.put("physiotherapietime", physiotherapietime);
        map.put("videourl", videourl);
        return map;
    }

    /**
     * 获取验证码的请求参数
     *
     * @param phone
     * @return
     */
    public static RequestBody getVerityParam(String phone) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("phone", Long.parseLong(phone));
        map.put("source", "app");
        String req = System.currentTimeMillis() + "_" + getThreeRandomNum();
        map.put("reqid", req);
        map.put("sign", EncryptUtils.encryptMD5ToString(req + "2re6HD3d9fa").toLowerCase());
        return setRequestBody(map);
    }

    private static RequestBody setRequestFileBody(HashMap<String, Object> map) {
        //File转RequestBody
        MediaType mediaType = MediaType.Companion.parse("text/x-markdown; charset=utf-8");
        File file = new File("");
        RequestBody fileBody = RequestBody.Companion.create(file, mediaType);
        return fileBody;
    }

    public static RequestBody setRequestBody(HashMap<String, Object> map) {
        MediaType mediaType = MediaType.Companion.parse("application/json;charset=utf-8");
        RequestBody stringBody = RequestBody.Companion.create(gson.toJson(map), mediaType);
        return stringBody;
    }

    public static String getThreeRandomNum() {
        int anInt = random.nextInt(1000);
        if (anInt < 10) {
            return "00".concat(String.valueOf(anInt));
        } else if (anInt < 100) {
            return "0".concat(String.valueOf(anInt));
        } else {
            return String.valueOf(anInt);
        }
    }


    public static HashMap<String, Object> getCommonParams() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("phone", SpSetting.getPhone());
        map.put("source", "app");
        String req = System.currentTimeMillis() + "_" + RxParams.getThreeRandomNum();
        map.put("reqid", req);
        map.put("sign", EncryptUtils.encryptMD5ToString(req + "2re6HD3d9fa").toLowerCase());
        return map;
    }
}
